<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>删除、创建节点</title>
	</head>
	<body>
		<input type="text" id="txt" />
		<input type="button" value="创建" id="addBtn"/>
		<input type="button" value="删除" id="deleteBtn"/>
		<ul id="ul"></ul>
		<script>
			//获取元素
			var txt=document.getElementById('txt');
			var delBtn=document.getElementById('deleteBtn');
			var addBtn=document.getElementById('addBtn');
			var ul=document.getElementById('ul');
			//给按钮添加点击事件
			addBtn.onclick=function(){
				var li=document.createElement('li');
				li.innerHTML=txt.value
				ul.appendChild(li);
			};
			delBtn.onclick=function(){
				ul.lastElementChild.remove();
			};
		</script>
	</body>
</html>
